﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using MyBlog.Model;
using SqlSugar;

namespace MyBlog.IRepository
{
    /// <summary>
    /// 基础仓储接口
    /// </summary>
    ///  ????
     public interface IBaseRepository<TEntity> where TEntity : class, new()
    {
        // 新增
        Task<bool> CreateAsync(TEntity entity);

        // 删除
        Task<bool> DeleteAsync(int id);

        // 删除
        Task<bool> DeleteAsync(string id);

        // 更新
        Task<bool> EditAsync(TEntity entity);

        // 查询
        Task<TEntity> FindAsync(int id);

        // 查询
        Task<TEntity> FindAsync(Expression<Func<TEntity, bool>> func);  // 表达式查询

        // 查询所有
        Task<List<TEntity>> QueryAsync();

        // 自定义查询条件
        Task<List<TEntity>> QueryAsync(Expression<Func<TEntity, bool>> func);

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="page"></param>
        /// <param name="size"></param>
        /// <param name="total"></param>
        /// <returns></returns>
        /// RefAsync: 通过引用传递的一个整数，表示查询结果的总记录数。该参数在方法内部会被赋值，并将其值传递回调用者。
        Task<List<TEntity>> QueryAsync(int page, int size, RefAsync<int> total);

        /// <summary>
        /// 自定义条件分页查询
        /// </summary>
        /// <param name="func"></param>
        /// <param name="page"></param>
        /// <param name="size"></param>
        /// <param name="total"></param>
        /// <returns></returns>
        Task<List<TEntity>> QueryAsync(Expression<Func<TEntity, bool>> func, int page, int size, RefAsync<int> total);
    }
}
